<?php
if (isset($_REQUEST['deviceId']) && isset($_REQUEST['regId'])) {
	require_once 'db.inc.php';
	$deviceId = $_REQUEST['deviceId'];
	$regId = $_REQUEST['regId'];
	$result = mysql_query("SELECT * FROM ".TABLE_PREFIX."devices WHERE deviceId = '$deviceId'") or die(mysql_error());
	if (mysql_num_rows($result) == 0) { // insert the new device
		mysql_query("INSERT INTO ".TABLE_PREFIX."devices (deviceId, regId) VALUES ('$deviceId', '$regId')") or die(mysql_error());
		header('HTTP/ 201 Created');
	} else {
		mysql_query("UPDATE ".TABLE_PREFIX."devices SET regId = '$regId' WHERE deviceId = '$deviceId'");
		header('HTTP/ 201 Updated');
	}
} else {
	header('HTTP/ 400 Bad Request');
}
?>